package kr.couponplay.android.activity;

import java.io.File;

import kr.couponplay.android.Constants;
import kr.couponplay.android.activity.deal.menu.SubMenuHelper;
import kr.couponplay.android.activity.deal.menu.TopMenuHelper;
import kr.couponplay.android.activity.message.MessageSubMenuHelper;
import kr.couponplay.android.activity.search.SearchSubMenuHelper;
import kr.couponplay.android.domain.DataContext;
import android.content.Context;
import android.util.Log;

public class CacheHelper {
	
    public static void clear(Context context) {
		TitleBarHelper.clear();
		TopMenuHelper.clear();
		SubMenuHelper.clear();
		MessageSubMenuHelper.clear();
		SearchSubMenuHelper.clear();
		DataContext.clear();
		clearApplicationCache(context.getCacheDir());
	}
    
    public static void clearApplicationCache(File cacheDir){
        if (cacheDir == null) {
            return;
        }

        File[] files = cacheDir.listFiles();
        try {
            for (File file : files) {
                if (file.isDirectory()) {
                    clearApplicationCache(file);
                } else {
                	file.delete();
                }
            }
        } catch(Exception e) {
        	Log.e(Constants.TAG, e.getMessage(), e);
        }
    }    
}
